package top.canyue.word_range_service.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import top.canyue.word_range.pojo.dto.PageDTO;
import top.canyue.word_range.pojo.dto.WordDto;
import top.canyue.word_range.pojo.query.WordQuery;
import top.canyue.word_range.pojo.vo.WordDetailVo;
import top.canyue.word_range.pojo.vo.WordMappingVo;
import top.canyue.word_range.result.Result;
import top.canyue.word_range_service.service.WordMappingService;
import top.canyue.word_range_service.service.WordService;

/**
 * 单词相关接口
 */
@RestController
@RequestMapping("/apiV1/word")
@RequiredArgsConstructor
public class WordController {
    final WordService wordService;
    final WordMappingService wordMappingService;

    /**
     * 添加单词
     */
    @PutMapping()
    public Result<Object> addWord(@RequestHeader String JWT , @RequestBody WordDto wordDto){
        return wordService.addWord(wordDto);
    }

    /**
     * 获得单词信息
     */
    @GetMapping
    public Result<WordDetailVo> getWordDetail(@RequestHeader String JWT, @RequestParam String word, @RequestParam String bookId){
        return wordService.getWordDetail(word,bookId);
    }

    /**
     * 更新单词信息
     */
    @PostMapping
    public Result<Object> updateWord(@RequestHeader String JWT ,@RequestBody WordDto wordDto){
        return wordService.updateWord(wordDto);
    }

    /**
     * 删除某本书中的一个单词
     */
    @DeleteMapping("/wordOnBook")
    public Result<Object> deleteWordOnBook(@RequestHeader String JWT, @RequestParam String word, @RequestParam String bookId){
        return wordService.deleteWordOnBook(word,bookId);
    }

    /**
     * 单词分页复杂查询
     */
    @GetMapping("/page")
    public PageDTO<WordMappingVo> getWordMappingPage(@RequestHeader String JWT, @RequestBody WordQuery wordQuery){
        return wordMappingService.getWordMappingPage(wordQuery);
    }

}
